package com.shelpe.services.sinbad.model;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
public class RptKeywordParam extends RptKeywordKey {
	public final static String FORMAT_DAY = "yyyy-MM-dd";

	public final static byte SOURCE_ALL = 0;
	public final static byte SOURCE_MOBILE = 1;
	public final static byte SOURCE_PC = 2;
	public final static byte SOURCE_SCORE = 3;

	private Long userId;
	private int day;// 最近天数
	private List<Long> keywordIds;// 关键词ids
	private List<Long> campaignIds;
	private List<Long> adgroupIds;
	private Long campaignId;
	private Long adgroupId;
	private Long keywordId;
	private String startDate;
	private String endDate;
	// private boolean impressions;
	// private boolean click;
	private int qscore;
	private int mobileQscore;
	private int clickDay;// 查点击量的天数
	private int impressionsDay;// 查展现量的天数

	public static RptKeywordParam init() {
		RptKeywordParam param = new RptKeywordParam();
		Date yesterday = DateUtils.addDays(DateUtils.truncate(new Date(), Calendar.DATE), -1);
		param.startDate = param.endDate = DateFormatUtils.format(yesterday, FORMAT_DAY);
		return param;
	}

	public void setupDate(String start, String end) {
		if (StringUtils.isNotBlank(start)) {
			this.startDate = start;
		}
		if (StringUtils.isNotBlank(end)) {
			this.endDate = end;
		}
	}

	public void setupDays(int days) {
		if (days > 0) {
			Date yesterday = DateUtils.addDays(DateUtils.truncate(new Date(), Calendar.DATE), -1);
			this.endDate = DateFormatUtils.format(yesterday, FORMAT_DAY);
			this.startDate = DateFormatUtils.format(DateUtils.addDays(yesterday, -days + 1), FORMAT_DAY);
		}
	}

	public void setupDevice(String device) {
		if (device != null) {
			if ("mobile".equals(device)) {
				this.setSource(SOURCE_MOBILE);
			} else if ("pc".equals(device)) {
				this.setSource(SOURCE_PC);
			} else if ("score".equals(device)) {
				this.setSource(SOURCE_SCORE);
			} else {
				this.setSource(SOURCE_ALL);
			}
		}
	}
}